package com.hqd.jjvm.classformat.constantpool;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;

@Getter
public class ConstantMethodhandleInfo extends ConstantPool {
	private Integer referenceKind;
	private Integer referenceIndex;

	public ConstantMethodhandleInfo(ConstantInfoType tag, ClassFile classFile) {
		super(tag, classFile);
		this.referenceKind = HexStrTransformUtil.parseHexToInt(classFile.readU1());
		checkKind();
		this.referenceIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		checkPoolIndex(referenceIndex);
	}

	private void checkKind() {
		if (referenceKind < 1 || referenceKind > 9) {
			throw new ClassFormatError(String.format("referenceKind %s 必须在1~9之间", referenceKind));
		}
	}

	@Override
	public Object getVal() {
		return super.getVal();
	}
}
